<template>
  <div>
    <el-tabs>
      <el-tab-pane label="登录账户设置">
        <el-form ref="formRef" :model="form" :rules="rules" label-width="100px" style="width:350px;margin-left:100px;">
          <el-form-item label="用户名" prop="username">
            <el-input v-model="form.username"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="form.password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="small" @click="submit">更新</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="个人详情">
        <user-info></user-info>
      </el-tab-pane>
      <el-tab-pane label="岗位信息">
        <job-info></job-info>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getEmplyeeBaseInfo } from '@/api/user'
import { saveUserDetailById } from '@/api/employees'
import UserInfo from './components/user-info.vue'
import JobInfo from './components/job-info.vue'
export default {
  name: 'Detail',
  components: { UserInfo, JobInfo },
  props: {
    id: {
      type: [String, Number],
      required: true
    }
  },
  data() {
    return {
      form: { username: '', password: '' },
      rules: {
        username: [{
          required: true, message: '用户名不能为空', trigger: 'blur'
        }],
        password: [{
          required: true, message: '密码不能为空', trigger: 'blur'
        }]

      }
    }
  },
  async created() {
    this.form = await getEmplyeeBaseInfo(this.id)
    this.form.password = ''
  },
  mounted() {},
  methods: {
    submit() {
      this.$refs.formRef.validate(async isOk => {
        if (!isOk) return
        await saveUserDetailById(this.form)
        this.$message.success('操作成功')
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
